<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            background-color: pink;
        }
    </style>
</head>
    
<body>
    <div></div>
    <script>
        //注意JS里面的样式采取驼峰命名法 比如fontSize 、backgroundColor
        //JS 修改 style 样式操作，产生的是行内样式，css权重比较高
        //1.获取元素 
        var div = document.querySelector('div');
        //2.注册事件 处理程序
        var flag = true;
        div.onclick = function () {
            //div.style里面的属性  采取驼峰命名法
            this.style.backgroundColor = 'purple';
            this.style.width = '200px';
            if (flag == true) {
                this.style.backgroundColor = 'purple';
                this.style.width = '200px';
                flag = false;
            } else {
                this.style.width = '200px';
                this.style.height = '200px';
                this.style.backgroundColor = 'pink';
                flag = true;
            }
            console.log(div + 1)
        };
    </script>

</body>

</html>